package com.gcmm;

import cn.hutool.core.swing.RobotUtil;

import java.awt.*;
import java.time.LocalDateTime;

/**
 * @Author: 张门马
 * @Description:
 * @Date: 2024/5/29 22:09
 */

public class Mouse {

    //false 关闭连击 true 开启连击
    public static boolean isMouseContinueClick = false;
    /**
     * @description: 鼠标连点
     * @title: continueClick
     * @param: [连点间隔 delay, 持续时间 seconds]
     * @author: gcmm
     * @return: void
     */
    public static void continueClick(Integer delay, Integer seconds) {
        // 设置连点间隔
        RobotUtil.setDelay(delay);

        // 结束时间
        LocalDateTime endTime = LocalDateTime.now().plusSeconds(seconds);

        // 开始连点
        while (isMouseContinueClick && LocalDateTime.now().isBefore(endTime)) {
            RobotUtil.click();
            RobotUtil.delay();
        }
    }

    /**
     * @description: 异步鼠标连点
     * @title: continueClickAsync
     * @author: gcmm
     * @return: void
     */
    public static void continueClickAsync() {
        new Thread(() -> Mouse.continueClick(1, 30)).start();
    }

    /**
     * @description: 切换鼠标连点状态
     * @title: changeMouseState
     * @author: gcmm
     * @return: boolean
     */
    public static boolean changeMouseState() {
        return isMouseContinueClick = !isMouseContinueClick;
    }


}